package com.wbw.ssb.service.impl;

import com.wbw.ssb.common.api.ResultCode;
import com.wbw.ssb.exception.ApiException;
import com.wbw.ssb.mbg.entity.System;
import com.wbw.ssb.mbg.mapper.SystemMapper;
import com.wbw.ssb.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @Author: guibo
 * @Description:
 * @Date: Created in 3:41 2021/5/19
 * @Modified By:
 */
@Service
public class SystemServiceImpl implements SystemService {
    @Autowired
    SystemMapper systemMapper;
    @Override
    public System getInfo() {
        List<System> system = systemMapper.select(c->c.limit(1));
        if(system==null||system.isEmpty()){
            throw new ApiException("未找到系统配置", ResultCode.FAILED);
        }
        return system.get(0);
    }

    @Override
    public Integer update(System system) {
        int count = systemMapper.updateByPrimaryKeySelective(system);
        if(count<=0){
            throw new ApiException("更新配置失败", ResultCode.FAILED);
        }
        return count;
    }
}
